<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        const obj = {
            uname:'zjl',
            age:44,
            hotbbin:['sing','jump','"rap','basketball'],
            hous:{
                uname:'baomi',
                age:20,
                hotbbin:['smoke','drink','makeHairStyle']
            }
        }

        // 创建一个空对象
        const ldh = {}

        // 封装函数
        function deepClone(newObj, oldobj){
            // 循环遍历拷贝到对象
            for(let key in oldobj){
                // 判断原对象里的一项是不是数组
                if(oldobj[key] instanceof Array){
                    // 如果是数组提前赋值
                    newObj[key] =[]
                    deepClone(newObj[key],oldobj[key])
                }
                // 
                else if(oldobj[key] instanceof Object){
                    // 果是对象提前赋值
                    newObj[key] = {}
                    deepClone(newObj[key],oldobj[key])
                }
                else{
                    // 把原对象里每一项的简单数据类型给新对象里
                    newObj[key] = oldobj[key]
                }
                
            }
        }

        deepClone(ldh,obj)

        ldh.hous.hotbbin[2] = '我能敲代码'
        ldh.uname = 'ldh'

        console.log(obj);
        console.log(ldh);
    </script>
    
</body>
</html>